<include file="public@header"/>
<style type="text/css">
    .pic-list li {
		border:1px;
        margin-bottom: 5px;
    }
</style>
<style>
.border-boxes {
    padding: 15px 20px;
    margin-bottom: 25px;
    background: #fff;
    -webkit-transition: all 0.3s ease-in-out;
    -moz-transition: all 0.3s ease-in-out;
    -o-transition: all 0.3s ease-in-out;
    transition: all 0.3s ease-in-out;
    word-wrap: break-word;
    word-break: break-all;
    border: solid 1px #eee;
}
</style>
<style>
.breadcrumb {
  padding: 8px 15px;
  margin-bottom: 20px;
  list-style: none;
  background-color: #f5f5f5;
  border-radius: 4px;
  font-size: 20px;
}
.breadcrumb > li + li:before {
    color: #CCCCCC;
    content: "-> ";
    padding: 0 5px;
	font-size: 30px;
}
</style>
<style>
.badge-warning{
	font-size:14px;
	background-color:#95a5a6;
	padding:7px 12px;
	margin-right:10px;
	cursor:pointer;
}
.badge-selected{
	background-color:#fa3;
}
</style>
<script type="text/html" id="photos-item-tpl">
    <li id="saved-image{id}">
        <input id="photo-{id}" type="hidden" name="photo_urls[]" value="{filepath}">
        <input class="form-control" id="photo-{id}-name" type="text" name="photo_names[]" value="{name}"
               style="width: 200px;border:0px;" title="图片名称">
        <img id="photo-{id}-preview" src="{url}" style="height:36px;width: 36px;"
             onclick="imagePreviewDialog(this.src);">
        <a href="javascript:(function(){$('#saved-image{id}').remove();})();">删除×</a>
    </li>
</script>
<script type="text/html" id="files-item-tpl">
    <li id="saved-file{id}">
        <input id="file-{id}" type="hidden" name="file_urls[]" value="{filepath}">
        <input class="form-control" id="file-{id}-name" type="text" name="file_names[]" value="{name}"
               style="width: 200px;border:0px;" title="文件名称">
        <a href="javascript:(function(){$('#saved-file{id}').remove();})();">删除×</a>
    </li>
</script>
</head>
<body>
<div class="wrap js-check-wrap">
	<ol class="breadcrumb">
		<li><a href="javascript:history.back(-1)">{$this_timetable_data['class_name']}-课堂资料</a></li>
		<li class="active">编辑资料</li>
	</ol>
	<div class="border-boxes">
		<h3>{$this_timetable_data['class_name']}资料</h3>
	</div>
    <form action="{:url('admin/class/class_blog_edit_post')}" method="post" class="form-horizontal js-ajax-form margin-top-20" onkeydown="if(event.keyCode==13)return false;">
		<input hidden name="blog_id" value="{$post['id']}"/>
		<input hidden id="times" name="post[timetable_id]" value="{$this_timetable_data['id']}"/>
		<input hidden name="post[class_id]" value="{$this_timetable_data['class_id']}"/>
        <div class="row">
            <div class="col-md-12">
                <table class="table table-bordered">
                    <tr>
                        <td class="form-inline">
							<div class="btn-group">
								<button id="times_view" class="btn btn-default">{$this_timetable_data['times']?'第'.$this_timetable_data['times'].'次课':'全部'}</button> <button data-toggle="dropdown" class="btn btn-default dropdown-toggle"><span class="caret"></span></button>
								<ul class="dropdown-menu">
									<li><a data-times="0" onclick="javascript:$('#times').val($(this).attr('data-times'));$('#times_view').html($(this).html());">全部</a></li>
									<foreach name="class_timetable_list" item="times_vo">
										<li><a data-times="{$times_vo['id']}" onclick="javascript:$('#times').val($(this).attr('data-times'));$('#times_view').html($(this).html());">第{$times_vo['times']}次课</a></li>
									</foreach>
								</ul>
							</div>
                            <input style="border:0px;width:80%;" class="form-control" type="text" name="post[title]"
                                   id="title" required value="{$post['title']}" placeholder="请输入标题" autocomplete="off"/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <script style="border:0px;" type="text/plain" id="content" name="post[content]">{$post['content']}</script>
                        </td>
                    </tr>
                    <tr>
                        <td style="height:50px;">
							<table>
							<tr>
								<td>
									<span class="badge-warning" style="background-color:#fff">选择标签：</span>
									<foreach name="blog_tags" item="tags_vo">
										<span onclick='javascript:badge_click(this);' class="badge badge-warning {:isset($tags_vo['selected'])&&$tags_vo['selected']?'badge-selected':''}" tags_id="{$tags_vo['id']}">{$tags_vo['name']}</span>
									</foreach>
								</td>
								<td><input class="form-control" placeholder="新建标签" style="border:0px;width:300%;" id="fast_new_tag" autocomplete="off"/></td>
                            <input id="tags" name="post[tags]"  value="{$this_timetable_data['tags']|default=''}" hidden />
							</tr>
							</table>
                        </td>
                    </tr>
                    <tr>
						<td>
							<ul id="photos" class="pic-list list-unstyled form-inline">
								<if condition="isset($post['more']['photos'])">
								<foreach name="$post['more']['photos']" item="photo_vo" key="photo_key">
									<li id="saved-image-{$photo_key}">
										<input id="photo-{$photo_key}" type="hidden" name="photo_urls[]" value="{$photo_vo['url']}">
										<input class="form-control" id="photo-{$photo_key}-name" type="text" name="photo_names[]" value="{$photo_vo['name']}"
											   style="width: 200px;border:0px;" title="图片名称">
										<img id="photo-{$photo_key}-preview" src="/upload/{$photo_vo['url']}" style="height:36px;"
											 onclick="imagePreviewDialog(this.src);">
										<a href="javascript:(function(){$('#saved-image-{$photo_key}').remove();})();">删除×</a>
									</li>
								</foreach>
								</if>
							</ul>
							<ul id="files" class="pic-list list-unstyled form-inline">
								<if condition="isset($post['more']['files'])">
								<foreach name="$post['more']['files']" item="file_vo" key="file_key">
									 <li id="saved-file-{$file_key}">
										<input id="file-{$file_key}" type="hidden" name="file_urls[]" value="{$file_vo['url']}">
										<input class="form-control" id="file-{$file_key}-name" type="text" name="file_names[]" value="{$file_vo['name']}"
											   style="width: 200px;border:0px;" title="文件名称">
										<a href="javascript:(function(){$('#saved-file-{$file_key}').remove();})();">删除×</a>
									</li>
								</foreach>
								</if>
							</ul>
                            <ul class="form-inline list-unstyled">
								<a href="javascript:uploadMultiImage('图片上传','#photos','photos-item-tpl');"
								   class="btn btn-default">添加图片</a>
								<a href="javascript:uploadMultiFile('附件上传','#files','files-item-tpl','file');"
								   class="btn btn-default">添加附件</a>
								<input type="checkbox" name="post[post_status]" value="1" {:$post['publish_time']==0?'':'checked'}>定时发布
								<input autocomplete="off" class="form-control js-bootstrap-datetime" type="text" name="post[publish_time]" value="{:$post['publish_time']==0?'':date('Y-m-d H:i:s',$post['publish_time'])}">
								<input type="checkbox" name="post[post_status_delete]" value="1" {:$post['delete_time']==2493046800?'':'checked'}>定时失效
								<input autocomplete="off" class="form-control js-bootstrap-datetime" type="text" name="post[delete_time]" value="{:$post['delete_time']==2493046800?'':date('Y-m-d H:i:s',$post['delete_time'])}">
								<input class="btn" type="checkbox" name="post[is_top]" value="1" {:$post['is_top']==1?'checked':''}>置顶
								<button type="submit" class="btn btn-primary js-ajax-submit pull-right">{:lang('SAVE')}</button>
								<a href="javascript:history.back()" class="btn btn-default pull-right">返回</a>
							</ul>	
                        </td>
					</tr>
                </table>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script type="text/javascript">
    //编辑器路径定义
    var editorURL = GV.WEB_ROOT;
</script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript">
    $(function () {

        editorcontent = new baidu.editor.ui.Editor();
        editorcontent.render('content');
        try {
            editorcontent.sync();
        } catch (err) {
        }

        $('.btn-cancel-thumbnail').click(function () {
            $('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
            $('#thumbnail').val('');
        });

    });
</script>
<script>
<!-- 选择标签事件 -->
		function badge_click(e){
			if($(e).hasClass('badge-selected')){
				$(e).removeClass('badge-selected');
			}
			else{
				$(e).addClass('badge-selected');
			}
			
			$("#tags").val('');
			var tags_value = [];
			$(".badge-selected").each(function(){
				tags_value.push($(this).attr('tags_id'));
			});
			$("#tags").val(tags_value.join(','));
		};

	$(function(){
		<!-- 快速添加标签事件 -->
		$("#fast_new_tag").keydown(function(e){
			if(e.which == 13){
				if($("#fast_new_tag").val()!=''){
					$.ajax({
						url: "{:url('admin/class/update_tags')}",
						type: 'post',
						data: {'class_id': {$this_timetable_data['class_id']},'name':$("#fast_new_tag").val()},
						success: function (result) {
							if(result.code==1){
								var tag_html = "<span onclick='javascript:badge_click(this);' class='badge badge-warning' tags_id='"+result.id+"'>"+$("#fast_new_tag").val()+"</span>";
								$(".badge-warning:last").after(tag_html);
								$("#fast_new_tag").val('');
								$("span[tags_id="+result.id+"]").click();
							}
							if(result.code==2){
								alert('相同的标签已经存在啦，直接点击选择吧！');
							}
							if(result.code==0){
								alert('新增标签失败啦，好阔怕！');
							}
						},
					});
				}
			}
		});
	});
</script>
</body>
</html>
